<template>
  <el-dialog
    :title="title"
    :visible.sync="dialogFormVisible"
    width="500px"
    @close="close"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
      <el-form-item label="标题" prop="meta.title">
        <el-input v-model="form.meta.title" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="名称" prop="name">
        <el-input v-model="form.name" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="路径" prop="path">
        <el-input v-model="form.path" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="Vue文件路径" prop="component">
        <el-input v-model="form.component" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="是否隐藏" prop="hidden">
        <el-select v-model="form.hidden" class="w">
          <el-option value="是" label="是"></el-option>
          <el-option value="否" label="否"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item
        label="是否一直显示节点"
        prop="alwaysShow"
        class="custemitem"
      >
        <el-select v-model="form.alwaysShow" class="w">
          <el-option value="是" label="是"></el-option>
          <el-option value="否" label="否"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="重定向" prop="redirect">
        <el-input v-model="form.redirect" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="图标" prop="icon">
        <el-input v-model="form.icon" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="是否固定" prop="affix">
        <el-select v-model="form.affix" class="w">
          <el-option value="是" label="是"></el-option>
          <el-option value="否" label="否"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="是否无缓存" prop="noKeepAlive">
        <el-select v-model="form.noKeepAlive" class="w">
          <el-option value="是" label="是"></el-option>
          <el-option value="否" label="否"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="Badge" prop="badge">
        <el-input v-model="form.badge" autocomplete="off"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { doEdit } from '@/api/menuManagement'

export default {
  name: 'MenuManagementEdit',
  data() {
    return {
      form: {
        name: '',
        path: '',
        mtitle:'',
        component: '',
        meta: {
          title: '',
          icon: '',
          affix: '',
          badge: '',
          noKeepAlive: '',
        },
        redirect: '',
        hidden: '',
        alwaysShow: '',
      },
      rules: {
        'meta.title': [{ required: true, trigger: 'blur', message: '请输入标题' }],
      },
      title: '',
      dialogFormVisible: false,
    }
  },
  created() {},
  methods: {
    showEdit(row) {
      if (!row) {
        this.title = '添加'
      } else {
        this.title = '编辑'
        this.form = Object.assign({}, row)
        //this.form.mtitle=
        //console.log(this.form)
      }
      this.dialogFormVisible = true
    },
    close() {
      this.$refs['form'].resetFields()
      //this.form = this.$options.data().form
      this.dialogFormVisible = false
    },
    save() {
      this.$refs['form'].validate(async (valid) => {
        if (valid) {
          const { msg } = await doEdit(this.form)
          this.$baseMessage(msg, 'success')
          this.$emit('fetch-data')
          this.close()
        } else {
          return false
        }
      })
    },
  },
}
</script>
